import { request } from "../utils";
import type { ResType } from "./shared";
const URL = '/takeAway_shops'

// export type ShopInfo = {
//     data:ShopItem[]
// }
export type ShopItem = {
    address: string,
    avatar: string,
    capita: number,
    category: string,
    delivery_fee: number,
    delivery_time: string,
    is_deleted: number,
    month_sales: number,
    mobile: string,
    score: number,
    status: number,
    title: string,
    _id: string
}
function getShopInfoOneAPI(shops_id: string) {
    return request<ResType<ShopItem>>({
        url: `${URL}/shopsInfo?shops_id=${shops_id}`,
        method: 'GET'
    })
}
function getShopInfoAPI() {
     
    return request<ResType<ShopItem[]>>({
        url: `${URL}/shopsInfo`,
        method: 'GET'
    })

}

type ShopCategory = {
    id: string
}
type Category = {
    shops_id: string,
    name: string,
    sort: number
}
function addShopCategory(params: Category) {
    return request<ResType<ShopCategory>>({
        url: `${URL}/addShopCategory`,
        method: 'POST',
        params
    })
}

export type CategoryItem = {
    is_deleted: number,
    name: string,
    shops_id: string,
    sort: number,
    _id: string
}

function getShopCategory(shops_id: string) {
    return request<ResType<CategoryItem[]>>({
        url: `${URL}/ShopCategory?shops_id=${shops_id}`,
        method: 'GET',
    })
}

// type Commodity = {
//     shops_id: string,  //商家id
//     category_id: string,//商家分类id
//     name: string,//商品名称
//     desc: string,//商品描述
//     imgUrl: string,//商品图片地址
//     price:number,//商品价格
//     discount:number,//商品折扣
//     remain_count: number,//商品库存
//     month_sell_count: number,//商品月售
//     total_sell_count: number,//商品总销量
//     is_on_sale: boolean//是否上架
// }

// export function addShopCommodity(commodity:Commodity) {
//     return request<ResType<string>>({
//         url: `${URL}/addCommodity`,
//         method: "POST",
//         params: commodity
//     })
// }
    // useEffect(() => {
    //     async function addShopC() {
    //         if (!shops_id) return
    //         try {
    //             const res = await addShopCommodity({
    //                 shops_id: "689f4c74ee97ef4a76c7f057",
    //                 category_id: "68a172888b0da441dc023f5d",
    //                 imgUrl: "https://mp-3a726716-b5d0-48b2-8dfd-a58d778e4fae.cdn.bspapp.com/takeAway/commodity/hmqz.webp",
    //                 name: "黄焖茄子",
    //                 desc: "新鲜美味，好吃不贵",
    //                 price: 15,
    //                 discount: 0.9,
    //                 remain_count: 999,
    //                 month_sell_count: 50,
    //                 total_sell_count: 50,
    //                 is_on_sale: true
    //             })
    //             console.log(res.data)

    //         } catch (error) {
    //             console.log(error + "商家信息获取错误")
    //         }
    //     }
    //     // addShopC()
    // }, [])

export type Commodity = {
    _id:string,//商品id
    shops_id: string,  //商家id
    category_id: string,//商家分类id
    name: string,//商品名称
    desc: string,//商品描述
    imgUrl: string,//商品图片地址
    price:number,//商品价格
    discount:number,//商品折扣
    discount_price:number,//商品折后价
    remain_count: number,//商品库存
    month_sell_count: number,//商品月售
    total_sell_count: number,//商品总销量
    is_on_sale: boolean,//是否上架
    count:number
}

export function getShopCommodity(shops_id:string,category_id:string){
    return request<ResType<Commodity[]>>({
        url:`${URL}/commodity`,
        method:"GET",
        params:{
            shops_id,
            category_id
        }
    })
}

export { getShopInfoAPI, addShopCategory, getShopCategory, getShopInfoOneAPI }